package com.hxd.otc.module.order.model;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.hxd.otc.R;
import com.hxd.otc.api.IOrderApi;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.order.bean.CheckImageBean;
import com.hxd.otc.module.order.bean.ComplainBean;
import com.hxd.otc.module.order.bean.ComplainTypeBean;
import com.hxd.otc.mvp.base.IBaseCallback;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.net.RetrofitManager;
import com.hxd.otc.utils.UIUtils;
import com.uber.autodispose.AutoDisposeConverter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * 包  名 :  com.hxd.otc.mvp.deal
 * 类  名 :  ComplainModel
 * 作  者 :  胡庆岭
 * 时  间 :  2018/6/8 15:38
 * 描  述 :  ${TODO} 上传凭证Model
 */
public class ComplainModel {
    private Callback mCallback;

    public interface Callback extends IBaseCallback {
        void proofResult(List<CheckImageBean> data);
    }

    public void loadProof() {
        List<CheckImageBean> data = new ArrayList<>();
        CheckImageBean bean = new CheckImageBean();
        bean.resImage = R.mipmap.icon_camera_add_image;
        data.add(bean);
        mCallback.proofResult(data);
    }

    public ComplainModel(@NonNull ComplainModel.Callback callback) {
        this.mCallback = callback;
    }

    public void complain(ComplainBean bean, BaseObserver observer, AutoDisposeConverter<BaseBean> converter) {
//        for (Map.Entry<String, Object> entry : bean.aliyunFileData.entrySet()) {
//            if (TextUtils.isEmpty(bean.url)) {
//                bean.url = entry.getValue().toString();
//            } else {
//                bean.url = bean.url + "," + entry.getValue().toString();
//            }
//        }
        RetrofitManager.getDefault()
                .create(IOrderApi.class)
                .complainAppeal(bean.orderId, bean.appealTypeId, bean.content, bean.url)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);

    }


    public List<ComplainTypeBean> getComplainType() {

        String[] appealType = UIUtils.getContext().getResources().getStringArray(R.array.appeal_type_array_new);
        int[] appealStatues = UIUtils.getContext().getResources().getIntArray(R.array.appeal_statues_array_new);
        List<ComplainTypeBean> complainTypeBeans = new ArrayList<>();
        for (int i = 0; i < appealType.length; i++) {
            ComplainTypeBean bean = new ComplainTypeBean();
            bean.id = appealStatues[i];
            bean.descri = appealType[i];
            complainTypeBeans.add(bean);
        }
        return complainTypeBeans;
    }

}
